package com.cltech.frame.transformer;

import org.hibernate.transform.BasicTransformerAdapter;
import org.springframework.core.convert.support.DefaultConversionService;

import java.util.List;

/**
 * SmartTransformer.
 * <p/>
 *
 * @author guanbo
 * @version 1.0.0.0
 */
public class SmartTransformer extends BasicTransformerAdapter {
    /**
     * defaultConversionService.
     */
    private static DefaultConversionService conversionService = new DefaultConversionService();
    /**
     * clazz.
     */
    private final Class clazz;

    /**
     * constructor.
     * @param clazz clazz
     */
    public SmartTransformer(final Class clazz) {
        this.clazz = clazz;
    }

    @Override
    public Object transformTuple(final Object[] tuple, final String[] aliases) {
        if (tuple != null && tuple.length > 0) {
            return conversionService.convert(tuple[0], clazz);
        }
        return null;
    }

    @Override
    public List transformList(final List list) {
        return super.transformList(list);
    }
}
